//
//  SelectFileCell.swift
//  Template
//
//  Created by zhibao on 2024/2/2.
//

import UIKit
public enum FileListCellType{
    //常规带点
    case Normal
    //选中
    case SelectYes
    //未选中
    case SelectNo
    //多选
    case Duoxuan
}
typealias SelectFileCelldealBlock = ()->()
class SelectFileCell: UITableViewCell {
    var dealBlock:SelectFileCelldealBlock?
    var nameLabel:UILabel!
    var sizeAndTimeLabel:UILabel!
    var iconImgView:UIImageView!
    var selectBtn:UIButton!
    var duoxuanLabel:UILabel!
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = .none
        self.backgroundColor = UIColor.clear
        
        let bgview = UIView()
        bgview.backgroundColor = MYColor.color(withHexString: "35393F", alpha: 0.6)
        self.contentView.addSubview(bgview)
        bgview.layer.cornerRadius = 15
        bgview.snp.makeConstraints { make in
            make.left.equalTo(15);
            make.top.equalTo(10);
            make.right.equalTo(-15);
            make.height.equalTo(70);
            make.bottom.equalTo(0);
        }
        iconImgView = UIImageView(image: UIImage(systemName: "waveform"))
        iconImgView.tintColor = UIColor.white
        iconImgView.layer.cornerRadius = 19
        iconImgView.clipsToBounds = true
        bgview.addSubview(iconImgView)
        iconImgView.snp.makeConstraints { make in
            make.left.equalTo(15)
            make.centerY.equalTo(bgview)
        }
        
        selectBtn = UIButton(type: .custom)
        selectBtn.setImage(UIImage(systemName: "ellipsis.rectangle"), for: .normal)
        selectBtn.tintColor = UIColor.white
        selectBtn.addTarget(self, action: #selector(selectBtnCilck), for: .touchUpInside)
        bgview.addSubview(selectBtn)
        selectBtn.snp.makeConstraints { make in
            make.right.equalTo(-15);
            make.centerY.equalTo(iconImgView);
            make.width.height.equalTo(40);
        }
        
        nameLabel = UILabel()
        nameLabel.font = MY_SCALE_SemiboldFONT(14)
        nameLabel.textColor = UIColor.white
        bgview.addSubview(nameLabel)
        nameLabel.snp.makeConstraints { make in
            make.left.equalTo(65);
            make.top.equalTo(15);
            make.right.equalTo(selectBtn.snp.left).offset(-15);
        }
        
        duoxuanLabel = UILabel()
        duoxuanLabel.text = ""
        duoxuanLabel.layer.cornerRadius = 10
        duoxuanLabel.font = MY_SCALE_RegularFONT(12)
        duoxuanLabel.layer.borderColor = UIColor.white.cgColor
        duoxuanLabel.layer.borderWidth = 0.5
        duoxuanLabel.clipsToBounds = true
        duoxuanLabel.textAlignment = .center
        duoxuanLabel.textColor = MYColor.color(withHexString: "#FC2F55")
        bgview.addSubview(duoxuanLabel)
        duoxuanLabel.snp.makeConstraints { make in
            make.centerY.equalTo(iconImgView);
            make.width.height.equalTo(20);
            make.right.equalTo(bgview).offset(-15);
        }
        
        sizeAndTimeLabel = UILabel()
        sizeAndTimeLabel.font = MY_SCALE_RegularFONT(11)
        sizeAndTimeLabel.textColor = MYColor.color(withHexString: "#ffffff")
        bgview.addSubview(sizeAndTimeLabel)
        sizeAndTimeLabel.snp.makeConstraints { make in
            make.left.right.equalTo(nameLabel);
            make.top.equalTo(nameLabel.snp.bottom).offset(7);
        }
    }
    @objc func selectBtnCilck(){
        if((self.dealBlock) != nil){
            self.dealBlock!()
        }
    }
    func updata(dic:[String:String],selectType:FileListCellType) {
        DLog(message: "eeee==\(dic)")
        selectBtn.isHidden = false
        selectBtn.isUserInteractionEnabled = true
        duoxuanLabel.isHidden = true
        if selectType == .Normal {
            selectBtn.isHidden = true
            selectBtn.setImage(UIImage(systemName: "ellipsis.rectangle"), for: .normal)
        }else if selectType == .SelectYes {
            selectBtn.setImage(UIImage(systemName: "checkmark.circle.fill"), for: .normal)
        }else if selectType == .SelectNo {
            selectBtn.setImage(UIImage(systemName: "checkmark.circle"), for: .normal)
        }
        nameLabel.text = Helper.removeEncode(dic["url"])
        sizeAndTimeLabel.text = "大小:\(dic["size"]!)   时长:\(dic["duration"]!)"
    }
    
    func updata(dic:[String:String],num:Int = 0) {
        selectBtn.isHidden = true
        duoxuanLabel.isHidden = false
        if(num > 0){
            duoxuanLabel.text = "\(num)"
            duoxuanLabel.backgroundColor = UIColor.white
        }else{
            duoxuanLabel.text = ""
            duoxuanLabel.backgroundColor = UIColor.black
        }
        nameLabel.text = Helper.removeEncode(dic["url"])
        sizeAndTimeLabel.text = "大小:\(dic["size"]!)   时长:\(dic["duration"]!)"
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

